/** index.js By Beginner Emain:zheng_jinfan@126.com HomePage:http://www.zhengjinfan.cn */

var tab;
var _tabId=0;
$('.admin-side-toggle').on('click', function () {
    var sideWidth = $('#admin-side').width();
    if (sideWidth === 320) {
        $('#admin-body').animate({
            left: '0'
        },"normal",function(){
            $("#_listBox").addClass("data-list-box");

        }); //admin-footer
        $('#admin-footer').animate({
            left: '0'
        });
        $('#admin-side').animate({
            width: '0'
        });
        $('.admin-side-toggle').animate({
            left: '5px'
        },"normal",function(){
            //$("#_listBox").addClass("data-list-box");
        });
        $('.body-top-nav,.padding30').animate({paddingLeft:"350px"})
        $("#_listBox").addClass("data-list-box");
    } else {
        $('#admin-body').animate({
            left: '320px'
        });
        $('#admin-footer').animate({
            left: '320px'
        });
        $('#admin-side').animate({
            width: '320px'
        });
        $('.admin-side-toggle').animate({
            left: '325px'
        },'normal',function(){
            $("#_listBox").removeClass("data-list-box");
        });
        $('.body-top-nav,.padding30').animate({paddingLeft:"30px"})
    }
});
layui.config({
    base: ADMIN+'/js/',
    version: new Date().getTime()
}).use(['element', 'layer', 'navbar', 'tab'], function () {
    var element = layui.element,
        $ = layui.jquery,layer = layui.layer,navbar = layui.navbar();
    //设置navbar
    // navbar.set({
    //     spreadOne: true,
    //     elem: '#admin-navbar-side',
    //     cached: true,
    //     data: navs
    // });
    //渲染navbar
    //navbar.render();
    //监听点击事件
    //navbar.on('click(side)', function (data) {
        //location.href=data.field.href;
        //console.log(data)
        // if(_tabId > 0){
        //     tab.deleteTab(_tabId);
        // }
        // tab.tabAdd(data.field);
        // _tabId = tab.getTabId(data.field.title);
   // });
    //清除缓存
    $('#clearCached').on('click', function () {
        navbar.cleanCached();
        layer.alert('清除完成!', { icon: 1, title: '系统提示' }, function () {
            location.reload();//刷新
        });
    });

    
    $('.admin-side-full').on('click', function () {
        if (localStorage.full == 0) {
            localStorage.full=1;
            var docElm = document.documentElement;
            //W3C
            if (docElm.requestFullscreen) {
                docElm.requestFullscreen();
            }
            //FireFox
            else if (docElm.mozRequestFullScreen) {
                docElm.mozRequestFullScreen();
            }
            //Chrome等
            else if (docElm.webkitRequestFullScreen) {
                docElm.webkitRequestFullScreen();
            }
            //IE11
            else if (elem.msRequestFullscreen) {
                elem.msRequestFullscreen();
            }
            layer.msg('按Esc即可退出全屏');
        } else {
            localStorage.full=0;
            if(document.exitFullscreen) {
                document.exitFullscreen();
            } else if(document.mozCancelFullScreen) {
                document.mozCancelFullScreen();
            } else if(document.webkitExitFullscreen) {
                document.webkitExitFullscreen();
            }
        }
    });

    // 监听顶部右侧导航
    element.on('nav(side-top-right)', function (elem) {
        // 修改skin
        if ($(this).attr('data-skin')) {
            document.cookie="skin="+$(this).attr('data-skin');
            skin();
        }
    });
    // 皮肤
    function skin() {
        var arr = document.cookie.match("(^| )skin=([^;]*)(;|$)");
        var skin = arr != null?arr[2]:"0";
        var body = $('body');
        body.removeClass('skin-0');
        body.removeClass('skin-1');
        body.removeClass('skin-2');
        body.addClass('skin-' + skin);
    }
    skin();
    //手机设备的简单适配
    var treeMobile = $('.site-tree-mobile'),
        shadeMobile = $('.site-mobile-shade');
    treeMobile.on('click', function () {
        $('body').addClass('site-mobile');
    });
    shadeMobile.on('click', function () {
        $('body').removeClass('site-mobile');
    });
});
layui.use('layer',function(){
    var $ = layui.jquery, layer = layui.layer;
    $('#_cache').click(function () {
        var href = $(this).data('href');
        document.cookie="skin=;expires="+new Date().toGMTString();
        layer.confirm('确认要清除缓存？', {icon: 3}, function () {
            $.post(href,{},function (data) {
                layer.msg(data.info, {icon: 6}, function (index) {
                    window.location.reload()
                });
            });
        });
    });
})